package thread.threaddemo;


import java.util.concurrent.locks.LockSupport;

/**
 * @Author: wenjingyuan
 * @Date: 2023/02/11/22:30
 * @Description:LockSupport
 */
public class LockSupport1 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            System.out.println("线程1开始执行");
            LockSupport.park();
            System.out.println("线程1结束执行");
        },"线程1");
        t1.start();

        Thread t2=new Thread(()->{
            System.out.println("线程2开始执行");
            LockSupport.park();
            System.out.println("线程2结束执行");
        },"线程2");
        t2.start();

        Thread t3=new Thread(()->{
            System.out.println("线程3开始执行");
            LockSupport.park();
            System.out.println("线程3结束执行");
        },"线程3");
        t3.start();

        //主线程唤醒三个线程
        Thread.sleep(1000);
        LockSupport.unpark(t1);
        Thread.sleep(1000);
        LockSupport.unpark(t2);
        Thread.sleep(1000);
        LockSupport.unpark(t3);
    }
}